﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：庄金冬 
    //
    // 文件名：BLL_Purchase.cs
    // 文件功能描述：采购操作业务逻辑类,,实现接口IBLL_Company,继承自类MarshalByRefObject
    // 创建标识：庄金冬2009-03-23
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Text;
using HZ.DrugTrade;
using HZ.DrugTrade.Model;
using System.Data;
using HZ.DrugTrade.DAL;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.BLL
{

    [Serializable]
    /// <summary>
    /// 采购操作业务逻辑类,实现接口IBLL_Company,继承自类MarshalByRefObject
    /// </summary>
    public class BLL_Purchase : MarshalByRefObject, IBLL.IBLL_Purchase
    {
        #region IBLL_Purchase 成员

        /// <summary>
        /// 添加一个采购单
        /// </summary>
        /// <param name="purchaseorder">采购单</param>
        /// <returns></returns>
        public int AddPurchaseOrder(HZ.DrugTrade.Model.PurchaseOrder purchaseorder)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseorder != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseorder.OrderName));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseorder.PlanPerson));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseorder.OrderID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseorder.HospitalID));
            Common.ThrowHelper.Throw(purchaseorder.TotalAmount != null);
            Common.ThrowHelper.Throw(purchaseorder.StartTime != null);
            //Common.ThrowHelper.Throw(purchaseorder.PlanEndTime != null);
            purchaseorder.PlanTime = DateTime.Now;
            if (purchaseorder.OrderStatus == null)
            {
                purchaseorder.OrderStatus = 0;
            }
            //int i = HZ.Data.DAL_Helper.OperateTable(purchaseorder, HZ.Data.TableOperator.Insert);
            //int i = int.Parse(HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(CommandType.Text, sql, HZ.Data.DBParameterFactory.GetIDbDataParameterList(parasnames, values).ToArray()).ToString());
            int i = 0;
            int count = int.Parse(HZ.Data.DbHelperFactory.Create().ExecuteScalar(string.Format("select count(ordername) from Tb_Purchaseorder where ordername='{0}' ", purchaseorder.OrderName)).ToString());
            if (count > 0)
            {
                i = 2;//采购单已存在
            }
            else
            {
                i = HZ.Data.DAL_Helper.OperateTableSQL(purchaseorder, HZ.Data.TableOperator.Insert, HZ.Data.DbHelperFactory.Create());
            }

            if (i == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = string.Format("添加采购单成功(采购单号:{0})", purchaseorder.OrderName), ClientIP = HZ.Fun.GetClientIP() });

            }
            return i;
        }

        /// <summary>
        /// 拷贝采购单，自定义名称，起始时间，备注
        /// 然后复制明细
        /// </summary>
        /// <param name="newPurchaseorder">新采购单信息</param>
        /// <param name="oldOrderID">源采购单ID</param>
        /// <returns>0失败，1成功</returns>
        public int CopyPurchaseOrder(HZ.DrugTrade.Model.PurchaseOrder newPurchaseorder, string oldOrderID,out string message)
        {
            message = string.Empty;
            if (AddPurchaseOrder(newPurchaseorder) == 1)
            {
                //HZ.DrugTrade.Model.Query.PurchaseOrderDetail where = new HZ.DrugTrade.Model.Query.PurchaseOrderDetail() { OrderID = oldOrderID };
                //int totalrecord;
                ////获取原采购单明细
                //IList<Model.View.PurchaseOrderDetail> List = HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.PurchaseOrderDetail, Model.Query.PurchaseOrderDetail>(where, 1, 0, out totalrecord);
                string strwhere = string.Empty;//存储组合查询条件
                string strsql = string.Format(@"select orderdetailid,procurecatalogid,goodsname from (select * from view_purchaseorderdetail where orderid = '{0}')
where companyid_ps not in (select distinct companyid_ps from tb_hospitalprocurecatalog where companyid_ps is not null)
or companyid_ps not in (select userid from tb_user where isusing = 1)", oldOrderID);
                DataTable dt = HZ.Data.DbHelperFactory.Create().ExecuteTable(strsql);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        strwhere += " and orderdetailid <> '" + dt.Rows[i]["orderdetailid"] + "'";
                        message += "产品编号为" + dt.Rows[i]["procurecatalogid"] + "产品名称为" + dt.Rows[i]["productname"] + "的产品的配送企业不存在或被禁用！请手动添加！";
                    }
                }
                string strsql1 = string.Format(@"select orderdetailid,procurecatalogid,goodsname from view_purchaseorderdetail where orderid = '{0}'
and procurecatalogid not in (select procurecatalogid from View_HospitalProcureCatalog where isusing = 1 AND HospitalID = '{1}' AND Hospital_IsUsing = 1)", oldOrderID, BLL_UserSession.GetCurrentUser().UserID);
                DataTable dt1 = HZ.Data.DbHelperFactory.Create().ExecuteTable(strsql1);
                if (dt1.Rows.Count > 0)
                {
                    for (int i = 0; i < dt1.Rows.Count; i++)
                    {
                        strwhere += " and orderdetailid <> '" + dt1.Rows[i]["orderdetailid"] + "'";
                        message += "产品编号为" + dt1.Rows[i]["procurecatalogid"] + "产品名称为" + dt1.Rows[i]["productname"] + "的产品不存在采购有效目录中或被禁用！请手动添加！";
                    }
                }
                string strsql2 = string.Format(@"select * from (
select procurecatalogid||hospitalid||companyid_sc||companyid_tb||companyid_ps statecount from view_purchaseorderdetail where orderid = '{0}'
) where statecount not in (select goodsid||hospitalid||companyid_sc||companyid_tb||companyid_ps from View_HospitalProcureCatalog where hospitalid='{1}')", oldOrderID, BLL_UserSession.GetCurrentUser().UserID);
                DataTable dt2 = HZ.Data.DbHelperFactory.Create().ExecuteTable(strsql2);
                if (dt2.Rows.Count > 0)
                {
                    for (int i = 0; i < dt2.Rows.Count; i++)
                    {
                        strwhere += " and orderdetailid <> '" + dt2.Rows[i]["orderdetailid"] + "'";
                        message += "产品编号为" + dt2.Rows[i]["procurecatalogid"] + "产品名称为" + dt2.Rows[i]["productname"] + "的产品配送关系被更换！请手动添加！";
                    }
                }
                //where.Append = strwhere;
                //获取原采购单明细
                //IList<Model.View.PurchaseOrderDetail> List = HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.PurchaseOrderDetail, Model.Query.PurchaseOrderDetail>(where, 1, 0, out totalrecord);
                DataTable strdt = HZ.Data.DbHelperFactory.Create().ExecuteTable(string.Format(@"select * from view_PurchaseOrderDetail where orderid = '{0}' {1}", oldOrderID, strwhere));
                IList<Model.View.PurchaseOrderDetail> List = HZ.DrugTrade.DAL2.DAL_Helper.CommonFillList<Model.View.PurchaseOrderDetail>(strdt);
                //重新组织数据
                IList<Model.PurchaseOrderDetail> OrderDetailList = new List<Model.PurchaseOrderDetail>();
                foreach (var item in List)
                {
                    PurchaseOrderDetail pod = new PurchaseOrderDetail();
                    pod.OrderID = newPurchaseorder.OrderID;
                    //复制采购单时，明细里价格用最新价格 add by zdc
                    decimal price = decimal.Parse(HZ.Data.DbHelperFactory.Create().ExecuteScalar("select Price from tb_hospitalprocurecatalog where procurecatalogid='" + item.ProcureCatalogID + "' and hospitalid = '" + item .HospitalID+ "'").ToString());
                    pod.Price = price;
                    pod.ProcureCatalogID = item.ProcureCatalogID;
                    pod.PurchaseCount = item.PurchaseCount;
                    pod.Amount = price * item.PurchaseCount;
                    pod.CompanyID_PS = item.CompanyID_PS;
                    pod.FlowID = item.FlowID;
                    OrderDetailList.Add(pod);
                }
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("插入新采购单明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
                //插入新采购单明细
                return AddPurchaseOrderDetail_Batch(OrderDetailList);
            }
            return 0;
        }


        /// <summary>
        /// 更新结算单
        /// </summary>
        /// <param name="purchaseorder">结算单</param>
        /// <returns></returns>

        public int UpdateInvoicePay(HZ.DrugTrade.Model.InvoicePay invoicepay)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoicepay != null);
            //Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicepay.InvoicePayNo));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicepay.InvoicePaySerialID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicepay.InvoicePayName));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicepay.Remarks));
            Common.ThrowHelper.Throw(invoicepay.InvoicePayTime != null);
            int state = DAL.DAL_InvoicePay.InvoicePayUpdate(invoicepay);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新结算单：{0};处理时间:{1};)", invoicepay.InvoicePayNo, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
            //BLL_UserSession.CheckSession();
            //Common.ThrowHelper.Throw(invoicepay != null);
            //Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicepay.InvoicePayNo));
            ////Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicepay.InvoicePaySerialID));
            //Common.ThrowHelper.Throw(invoicepay.ActualAmount != null);
            //Model.InvoicePay updatemodel = HZ.Data.DAL_Helper.GetModelByID(invoicepay);
            //updatemodel.ActualAmount = invoicepay.ActualAmount;
            //updatemodel.InvoicePayNo = invoicepay.InvoicePayNo;
            //return HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
        }
        /// <summary>
        /// 更新采购单起始时间
        /// </summary>
        /// <param name="purchaseorder">采购单</param>
        /// <returns></returns>
        public int UpdatePurchaseOrder_StartTime(HZ.DrugTrade.Model.PurchaseOrder purchaseorder)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseorder != null);
            Common.ThrowHelper.Throw(purchaseorder.StartTime != null);
            Model.PurchaseOrder updatemodel = HZ.Data.DAL_Helper.GetModelByID(purchaseorder);
            updatemodel.StartTime = purchaseorder.StartTime;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state ==1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购单起始时间：{0};处理时间:{1};)", purchaseorder.OrderName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 更新采购单结束时间
        /// </summary>
        /// <param name="purchaseorder">采购单</param>
        /// <returns></returns>
        public int UpdatePurchaseOrder_EndTime(HZ.DrugTrade.Model.PurchaseOrder purchaseorder)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseorder != null);
            //Common.ThrowHelper.Throw(purchaseorder.PlanEndTime != null);
            Model.PurchaseOrder updatemodel = HZ.Data.DAL_Helper.GetModelByID(purchaseorder);
            //updatemodel.PlanEndTime = purchaseorder.PlanEndTime;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购单结束时间：{0};处理时间:{1};)", purchaseorder.OrderName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 更新采购单名称
        /// </summary>
        /// <param name="purchaseorder">采购单</param>
        /// <returns></returns>
        public int UpdatePurchaseOrder_OrderName(HZ.DrugTrade.Model.PurchaseOrder purchaseorder)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseorder != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseorder.OrderName));
            Model.PurchaseOrder updatemodel = HZ.Data.DAL_Helper.GetModelByID(purchaseorder);
            updatemodel.OrderName = purchaseorder.OrderName;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购单名称：{0};处理时间:{1};)", purchaseorder.OrderName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 更新采购单
        /// </summary>
        /// <param name="purchaseorder">采购单</param>
        /// <returns></returns>
        public int UpdatePurchaseOrder(HZ.DrugTrade.Model.PurchaseOrder purchaseorder)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseorder != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseorder.OrderName));
            Common.ThrowHelper.Throw(purchaseorder.StartTime != null);
            //Common.ThrowHelper.Throw(purchaseorder.PlanEndTime != null);
            //Model.PurchaseOrder updatemodel = HZ.Data.DAL_Helper.GetModelByID<PurchaseOrder>(purchaseorder);
            //updatemodel.OrderName = purchaseorder.OrderName;
            //updatemodel.StartTime = purchaseorder.StartTime;
            //updatemodel.PlanEndTime = purchaseorder.PlanEndTime;
            //return HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update
            int state = HZ.Data.DAL_Helper.UpdateModel<PurchaseOrder>(purchaseorder);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购单：{0};处理时间:{1};)", purchaseorder.OrderName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 插入一个采购单明细
        /// </summary>
        /// <param name="PurchaseOrderDetail">采购单</param>
        /// <returns>0失败1成功</returns>
        public int AddPurchaseOrderDetail(HZ.DrugTrade.Model.PurchaseOrderDetail purchaseOrderDetail)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseOrderDetail != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseOrderDetail.CompanyID_PS));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseOrderDetail.FlowID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseOrderDetail.OrderDetailID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseOrderDetail.OrderID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(purchaseOrderDetail.ProcureCatalogID));
            purchaseOrderDetail.CurrentNode = "";
            int state = HZ.Data.DAL_Helper.OperateTable(purchaseOrderDetail, HZ.Data.TableOperator.Insert);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("插入一个采购单明细：{0};处理时间:{1};)", purchaseOrderDetail.OrderDetailID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 更新采购流程
        /// </summary>
        /// <param name="PurchaseOrderDetail">采购单</param>
        /// <returns></returns>
        public int UpdatePurchaseOrderDetail_CurrentNode(HZ.DrugTrade.Model.PurchaseOrderDetail PurchaseOrderDetail)
        {
            BLL_UserSession.CheckSession();
            Model.PurchaseOrderDetail updatemodel = HZ.Data.DAL_Helper.GetModelByID(PurchaseOrderDetail);
            updatemodel.CurrentNode = PurchaseOrderDetail.CurrentNode;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购流程：{0};处理时间:{1};)", PurchaseOrderDetail.OrderDetailID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }



        /// <summary>
        /// 更新采购数量
        /// </summary>
        /// <param name="PurchaseOrderDetail">采购单详细</param>
        /// <returns></returns>
        public int UpdatePurchaseOrderDetail_PurchaseCount(HZ.DrugTrade.Model.PurchaseOrderDetail purchaseOrderDetail)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseOrderDetail != null);
            Model.PurchaseOrderDetail updatemodel = HZ.Data.DAL_Helper.GetModelByID(purchaseOrderDetail);
            updatemodel.PurchaseCount = purchaseOrderDetail.PurchaseCount;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购数量：{0};处理时间:{1};)", purchaseOrderDetail.OrderDetailID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 更新采购产品确认状态
        /// </summary>
        /// <param name="PurchaseOrderDetail">采购单详细</param>
        /// <returns></returns>
        public int UpdatePurchaseOrderDetail_OrderDetailState(HZ.DrugTrade.Model.PurchaseOrderDetail purchaseOrderDetail)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(purchaseOrderDetail != null);
            Model.PurchaseOrderDetail updatemodel = HZ.Data.DAL_Helper.GetModelByID(purchaseOrderDetail);
            updatemodel.OrderDetailState = purchaseOrderDetail.OrderDetailState;
            int state = HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新采购产品确认状态：{0};处理时间:{1};)", purchaseOrderDetail.OrderDetailID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 提交采购单
        /// </summary>
        /// <param name="PurchaseOrderDetail">采购单详细</param>
        /// <returns></returns>
        public int UpdatePurchaseOrderDetail_Submit(HZ.DrugTrade.Model.PurchaseOrder purchaseOrder)
        {
            BLL_UserSession.CheckSession();
            int i = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_Submit(purchaseOrder);

            if (1 == i)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = string.Format("提交采购单成功(采购单ID:{0})", purchaseOrder.OrderID), ClientIP = HZ.Fun.GetClientIP() });

            }
            return i;
        }


        /// <summary>
        /// 企业出库更新
        /// </summary>
        /// <param name="distribution">出库信息</param>
        /// <param name="distributionBatchRecord">出库单信息</param>
        /// <returns></returns>
        /// <remarks>
        /// 应只更新需要的信息。
        /// </remarks>
        public int UpdatePurchaseOrderDetail_Distribution(HZ.DrugTrade.Model.Distribution distribution, HZ.DrugTrade.Model.DistributionBatchRecord distributionBatchRecord)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(distribution != null);
            Common.ThrowHelper.Throw(distributionBatchRecord != null);
            //// 插入配送表
            //string uid = Guid.NewGuid().ToString();
            //distribution.DistributionSerialID = uid;
            //distributionBatchRecord.DistributionSerialID = uid;
            //int a = HZ.Data.DAL_Helper.OperateTable(distribution, HZ.Data.TableOperator.Insert);

            //if (a != 1)
            //    return a;
            //a = HZ.Data.DAL_Helper.OperateTable(distributionBatchRecord, HZ.Data.TableOperator.Insert);
            //if (a != 1)
            //    return a;

            //// 更新缓存

            //Model.PurchaseOrderDetail updatemodel = new HZ.DrugTrade.Model.PurchaseOrderDetail() { OrderDetailID = distribution.OrderDetailID };
            //updatemodel.DistributeCount = distribution.DistributeCount;
            //// 更新节点
            //updatemodel = HZ.Data.DAL_Helper.GetModelByID(updatemodel);
            //return HZ.Data.DAL_Helper.OperateTable(updatemodel, HZ.Data.TableOperator.Update);

            IList<HZ.DrugTrade.Model.Distribution> DistributionList = new List<HZ.DrugTrade.Model.Distribution>();
            DistributionList.Add(distribution);
            IList<HZ.DrugTrade.Model.DistributionBatchRecord> DistributionBatchRecordList = new List<HZ.DrugTrade.Model.DistributionBatchRecord>();
            DistributionBatchRecordList.Add(distributionBatchRecord);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_Distribution_Batch(DistributionList, DistributionBatchRecordList);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("企业出库更新：{0};处理时间:{1};)", distribution.OrderDetailID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;

        }

        /// <summary>
        /// 批量企业出库更新 
        /// </summary>
        /// <param name="DistributionList">出库信息列表</param>
        /// <param name="DistributionBatchRecordList">出库单信息列表</param>
        /// <returns></returns>
        /// <remarks>
        /// 应只更新需要的信息。
        /// </remarks>
        public int UpdatePurchaseOrderDetail_Distribution_Batch(IList<HZ.DrugTrade.Model.Distribution> distributionList, IList<HZ.DrugTrade.Model.DistributionBatchRecord> distributionBatchRecordList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(distributionList != null);
            Common.ThrowHelper.Throw(distributionBatchRecordList != null);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_Distribution_Batch(distributionList, distributionBatchRecordList);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量企业出库更新;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;
        }

        /// <summary>
        /// 批量企业出库修改
        /// </summary>
        /// <param name="DistributionList">出库信息列表</param>
        /// <param name="DistributionBatchRecordList">出库单信息列表</param>
        /// <returns></returns>
        /// <remarks>
        /// 应只更新需要的信息。
        /// </remarks>
        public int EditPurchaseOrderDetail_Distribution_Batch(IList<HZ.DrugTrade.Model.Distribution> distributionList, IList<HZ.DrugTrade.Model.DistributionBatchRecord> distributionBatchRecordList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(distributionList != null);
            Common.ThrowHelper.Throw(distributionBatchRecordList != null);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.EditPurchaseOrderDetail_Distribution_Batch(distributionList, distributionBatchRecordList);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量企业出库修改;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;
        }

        /// <summary>
        /// 批量企业出库删除
        /// </summary>
        /// <param name="DistributionList">出库信息列表</param>
        /// <returns></returns>
        /// <remarks>
        /// 应只更新需要的信息。
        /// </remarks>
        public int DeletePurchaseOrderDetail_Distribution_Batch(IList<HZ.DrugTrade.Model.Distribution> distributionList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(distributionList != null);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.DeletePurchaseOrderDetail_Distribution_Batch(distributionList);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量企业出库删除;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;
        }

        /// <summary>
        /// 批量更新医疗机构入库【验收】数量(0.不成功,1.成功,)
        /// </summary>
        /// <param name="distributionList">配送情况</param>
        /// <returns>0失败1成功</returns>
        public int UpdatePurchaseOrderDetail_Warehouse_Batch(IList<HZ.DrugTrade.Model.Distribution> distributionList, string hospitalID)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(distributionList != null);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_Warehouse_Batch(distributionList, hospitalID);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量更新医疗机构入库：{0};处理时间:{1};)", hospitalID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;
        }

        /// <summary>
        /// 批量更新医疗机构入库【验收】数量(0.不成功,1.成功,)
        /// </summary>
        /// <param name="distributionList">配送情况</param>
        /// <returns>0失败1成功</returns>
        public int UpdatePurchaseOrderDetail_Warehouse_Batch2(IList<HZ.DrugTrade.Model.View.Distribution> DistributionList, string hospitalID, string hospitalName, string hospitalAreaID)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(DistributionList != null);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_Warehouse_Batch2(DistributionList, hospitalID, hospitalName, hospitalAreaID);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量更新医疗机构入库：{0};处理时间:{1};)", hospitalName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;
        }

        /// <summary>
        /// 批量更新是否开票信息(0.不成功,1.成功,)
        /// </summary>
        /// <param name="distributionList">配送情况</param>
        /// <returns>0失败1成功</returns>
        public int UpdatePurchaseOrderDetail_Invoice_Batch(IList<HZ.DrugTrade.Model.Distribution> distributionList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(distributionList != null);
            int flag = 0;
            flag = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_Invoice_Batch(distributionList);
            if(flag == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量更新是否开票信息;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return flag;
        }

        /// <summary>
        /// 分页获取采购单信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.PurchaseOrder> GetPurchaseOrderByWhere(HZ.DrugTrade.Model.Query.PurchaseOrder where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.PurchaseOrder, Model.Query.PurchaseOrder>(where, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 分页获取采购单信息【未确认】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.PurchaseOrder_NoConfirm> GetPurchaseOrder_NoConfirmByWhere(HZ.DrugTrade.Model.Query.PurchaseOrder_NoConfirm where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.PurchaseOrder_NoConfirm, Model.Query.PurchaseOrder_NoConfirm>(where, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 分页获取采购单明细信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.PurchaseOrderDetail> GetPurchaseOrderDetailByWhere(HZ.DrugTrade.Model.Query.PurchaseOrderDetail where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);
            string strsql = string.Format("SELECT a.*,case a.OrderDetailState when 0 then '未提交' when 1 then '已提交' when 2 then '已确认' when 3 then '拒绝配送' end  as orderdetailstatedc FROM View_PurchaseOrderDetail a   WHERE 1=1 {0}", condition);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(strsql, pagesize) { CurrentPage = currentpage };
            DataTable dt = pdes.GetSpecailPage();
            totalrecord = pdes.TotalCount;
            return HZ.DrugTrade.DAL2.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.PurchaseOrderDetail>(dt);
        }

        /// <summary>
        /// 获取采购单中某家企业产品的总金额
        /// </summary>
        /// <param name="strOrderID"></param>
        /// <param name="strCompanyID_PS"></param>
        /// <returns></returns>
        public decimal GetPurchaseOrderAmountOfCompany(string strOrderID, string strCompanyID_PS)
        {
            string sql = "SELECT SUM(Amount) as Amount FROM View_PurchaseOrderDetail  WHERE 1=1 AND OrderID='" + strOrderID + "' AND CompanyID_PS='" + strCompanyID_PS + "'";
            decimal totalAmount = (decimal)HZ.Data.DbHelperFactory.Create().ExecuteScalar(sql);

            return totalAmount;
        }

        /// <summary>
        /// 分页获取采购单信息【未配送】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.PurchaseOrderDetail> GetPurchaseOrderDetail_NoDistributeByWhere(HZ.DrugTrade.Model.Query.PurchaseOrderDetail where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            //where.OrderDetailState = 2;  modfiy by ysm 20130201 注释说明 ： 去除订单确认步骤，无需确认直接配送 ，配送后订单状态为已确认

            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);

            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_PurchaseOrderDetail  WHERE DistributeCount < PurchaseCount  {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);
            pdes.CurrentPage = currentpage;
            totalrecord = pdes.TotalCount;

            System.Data.DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.PurchaseOrderDetail>(dt);

        }

        /// <summary>
        /// 分页获取采购单明细信息【已配送】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Distribution> GetPurchaseOrderDetail_DistributeByWhere(HZ.DrugTrade.Model.Query.Distribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
      

            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);

            //HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE [DistributionSerialID] IS NOT NULL AND [DistributeState]=0   {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE 1=1 and PurchaseCount>0 {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);

            pdes.CurrentPage = currentpage;
            totalrecord = pdes.TotalCount;

            System.Data.DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.Distribution>(dt);
        }



        /// <summary>
        /// 分页获取采购单明细信息【已验收】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Distribution> GetPurchaseOrderDetail_AcceptByWhere(HZ.DrugTrade.Model.Query.Distribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            where.OrderDetailState = 2;
            where.DistributeState = 1;

            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);

            // HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE [DistributionSerialID] IS NOT NULL AND [DistributeState]=1 AND  ReturnCount < WarehouseCount {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE NVL(Dis_DistributeCount, 0) > 0  {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);

            pdes.CurrentPage = currentpage;
            totalrecord = pdes.TotalCount;

            System.Data.DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.Distribution>(dt);
        }

        /// <summary>
        /// 分页获取采购单明细信息【余量查询】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Distribution> GetPurchaseOrderDetail_BalanceByWhere(HZ.DrugTrade.Model.Query.Distribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            where.OrderDetailState = 2;

            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);

            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE DistributionSerialID IS NOT NULL AND DistributeState=0   {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);
            pdes.CurrentPage = currentpage;
            totalrecord = pdes.TotalCount;

            System.Data.DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.Distribution>(dt); ;
        }

        /// <summary>
        /// 分页获取采购单明细信息【过期查询】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Distribution> GetPurchaseOrderDetail_OverdueByWhere(HZ.DrugTrade.Model.Query.Distribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);

            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE  OrderDetailState = '1' AND DistributionSerialID IS NULL AND PlanEndTime<=sysdate {0} ", condition, typeof(HZ.DrugTrade.Model.View.Distribution).Name), pagesize);
            pdes.CurrentPage = currentpage;
            totalrecord = pdes.TotalCount;

            System.Data.DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.Distribution>(dt); ;
        }


        /// <summary>
        /// 分页获取出库明细信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Distribution> GetDistribution_Page(HZ.DrugTrade.Model.Query.Distribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            //  return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.Distribution, Model.Query.Distribution>(where, currentpage, pagesize, out totalrecord);
            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);

            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM View_{1} WHERE   1=1 {0} ", condition, typeof(Model.View.Distribution).Name), pagesize);
            pdes.CurrentPage = currentpage;
            totalrecord = pdes.TotalCount;

            System.Data.DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.Distribution>(dt); ;
        }

        /// <summary>
        /// 批量插入采购单明细
        /// </summary>
        /// <returns>0失败1成功</returns>
        public int AddPurchaseOrderDetail_Batch(IList<HZ.DrugTrade.Model.PurchaseOrderDetail> PurchaseOrderDetailList)
        {
            BLL_UserSession.CheckSession();
            int state = DAL.DAL_PurchaseOrderDetail.AddPurchaseOrderDetail_Batch(PurchaseOrderDetailList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量插入采购单明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 批量更新采购数量
        /// </summary>
        public int UpdatePurchaseOrderDetail_PurchaseCount_Batch(IList<HZ.DrugTrade.Model.PurchaseOrderDetail> PurchaseOrderDetailList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in PurchaseOrderDetailList)
            {
                HZ.Common.ThrowHelper.Throw(item.OrderDetailID != null, "采购单ID能不为空");
                HZ.Common.ThrowHelper.Throw(item.PurchaseCount != null, "采购明细数量不为空");
                HZ.Common.ThrowHelper.Throw(item.Amount != null, "采购明细总价不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.UpdatePurchaseOrderDetail_PurchaseCount_Batch(PurchaseOrderDetailList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量更新采购数量;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 删除采购单
        /// </summary>
        /// <returns>0失败1成功</returns>
        public int DeletePurchaseOrder(HZ.DrugTrade.Model.PurchaseOrder PurchaseOrder)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(PurchaseOrder.OrderID), "采购单ID不能空");
            int i=DAL.DAL_PurchaseOrder.DeletePurchaseOrder(PurchaseOrder);
            if (1 == i)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = string.Format("删除采购单成功(采购单ID:{0})", PurchaseOrder.OrderID)});

            }
            return i;
        }
        /// <summary>
        /// 删除采购单
        /// </summary>
        /// <returns>0失败1成功</returns>
        public int DropPurchaseOrder(HZ.DrugTrade.Model.PurchaseOrder PurchaseOrder)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(PurchaseOrder.OrderID), "采购单ID不能空");
            int i = DAL.DAL_PurchaseOrder.DropPurchaseOrder(PurchaseOrder);
            if (1 == i)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog() { OperateMessage = string.Format("撤废采购单成功(采购单ID:{0})", PurchaseOrder.OrderID) });

            }
            return i;
        }
        /// <summary>
        /// 批量删除采购单明细
        /// </summary>
        /// <returns>0失败1成功</returns>
        public int DeletePurchaseOrderDetail_Batch(IList<HZ.DrugTrade.Model.PurchaseOrderDetail> PurchaseOrderDetailList)
        {
            BLL_UserSession.CheckSession();
            int state = DAL.DAL_PurchaseOrderDetail.DeletePurchaseOrderDetail_Batch(PurchaseOrderDetailList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量删除采购单明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 批量确认采购单明细
        /// </summary>
        /// <param name="PurchaseOrderDetailList">采购单明细列表</param>
        /// <returns></returns>
        public int ConfirmPurchaseOrderDetail_Batch(IList<HZ.DrugTrade.Model.PurchaseOrderDetail> PurchaseOrderDetailList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in PurchaseOrderDetailList)
            {
                HZ.Common.ThrowHelper.Throw(item.OrderDetailID != null, "采购单ID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.ConfirmPurchaseOrderDetail_Batch(PurchaseOrderDetailList, 2);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量确认采购单明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 拒绝确认采购单明细
        /// </summary>
        /// <param name="PurchaseOrderDetailList">采购单明细列表</param>
        /// <remarks>
        /// 采购单明细ID不能空
        /// </remarks>
        /// <returns></returns>
        public int RefuseConfirmPurchaseOrderDetail_Batch(IList<PurchaseOrderDetail> PurchaseOrderDetailList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in PurchaseOrderDetailList)
            {
                HZ.Common.ThrowHelper.Throw(item.OrderDetailID != null, "采购单ID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.ConfirmPurchaseOrderDetail_Batch2(PurchaseOrderDetailList, 3);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("拒绝确认采购单明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 批量撤销消确认采购单明细
        /// </summary>
        /// <param name="PurchaseOrderDetailList">采购单明细列表</param>
        /// <returns></returns>
        public int UnconfirmPurchaseOrderDetail_Batch(IList<HZ.DrugTrade.Model.PurchaseOrderDetail> PurchaseOrderDetailList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in PurchaseOrderDetailList)
            {
                HZ.Common.ThrowHelper.Throw(item.OrderDetailID != null, "采购单ID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.ConfirmPurchaseOrderDetail_Batch(PurchaseOrderDetailList, 0);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量撤销消确认采购单明细;处理时间:{1};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 添加一个退货单(0.不成功,1.成功,)
        /// </summary>
        /// <param name="returnMerchandise">退货单</param>
        /// <returns>(0.不成功,1.成功,)</returns>
        public int AddReturnMerchandise(HZ.DrugTrade.Model.ReturnMerchandise returnMerchandise)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(returnMerchandise != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(returnMerchandise.ReturnSerialID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(returnMerchandise.ReturnName));
            //Common.ThrowHelper.Throw(!string.IsNullOrEmpty(returnMerchandise.ReturnSerialID));
            //Common.ThrowHelper.Throw(!string.IsNullOrEmpty(returnMerchandise.ReturnSum));
            //Common.ThrowHelper.Throw(returnMerchandise.ReturnTime != null);
            //Common.ThrowHelper.Throw(returnMerchandise.ReturnCount != null);

            // returnMerchandise.ReturnState = 0;
            int state = HZ.Data.DAL_Helper.OperateTableSQL(returnMerchandise, HZ.Data.TableOperator.Insert);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("添加一个退货单：{0};处理时间:{1};)", returnMerchandise.ReturnName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 获取采购单明细可退货数量
        /// </summary>
        /// <param name="OrderDetailID">采购单明细编号</param>
        /// <returns>可退货数量</returns>
        public int GetLeftCountForReturn(string OrderDetailID)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(OrderDetailID));

            return 0;

            //return HZ.Data.DAL_Helper.OperateTable(returnMerchandise, HZ.Data.TableOperator.Insert);
        }



        /// <summary>
        /// 批量确认退货单(0.不成功,1.成功,)
        /// </summary>
        /// <param name="returnMerchandiseList">退货单集合</param>
        /// <returns>(0.不成功,1.成功,)</returns>
        public int ConfirmReturnMerchandise_Batch(IList<ReturnMerchandiseDetail> list)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in list)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.ReturnSerialDetailID), "退货单流水号不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.ConfirmReturnMerchandise_Batch(list);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量确认退货单;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 批量拒绝退货单(0.不成功,1.成功,)
        /// </summary>
        /// <param name="returnMerchandiseList">退货单集合</param>
        /// <returns>(0.不成功,1.成功,)</returns>
        public int RefuseReturnMerchandise_Batch(IList<HZ.DrugTrade.Model.ReturnMerchandiseDetail> returnMerchandiseList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in returnMerchandiseList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.ReturnSerialDetailID), "退货单流水号不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.RefuseReturnMerchandise_Batch(returnMerchandiseList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量拒绝退货单;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        ///// <summary>
        ///// 分页获取退货详情信息
        ///// </summary>
        ///// <param name="where">查询实体</param>
        ///// <param name="currentpage">当前页</param>
        ///// <param name="pagesize">页面大小</param>
        ///// <param name="totalrecord">记录总数</param>
        ///// <returns></returns>
        //public IList<HZ.DrugTrade.Model.View.ReturnDistribution> GetReturnDistribution_NoConfirmByWhere(HZ.DrugTrade.Model.Query.ReturnDistribution where, int currentpage, int pagesize, out int totalrecord)
        //{
        //    return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.ReturnDistribution, Model.Query.ReturnDistribution>(where, currentpage, pagesize, out totalrecord);
        //}


        /// <summary>
        /// 添加发票信息 [同时关联配送单信息列表]
        /// </summary>
        /// <param name="invoice">发票信息 【InvoiceSerialID,InvoiceID,CompanyID_PS,HospitalID,InvoiceTime,TotalAmount必填】</param>
        /// <param name="distributionList">出库单信息列表【DistributionSerialID必填】</param>
        /// <returns></returns>
        public int AddInvoice_Distribution(HZ.DrugTrade.Model.Invoice invoice, IList<HZ.DrugTrade.Model.Distribution> distributionList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoice != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.InvoiceID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.CompanyID_PS));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.HospitalID));
            Common.ThrowHelper.Throw(invoice.InvoiceTime != null);
            Common.ThrowHelper.Throw(invoice.TotalAmount != null);

            //页面中若不传入发票号，则自动生成
            if (string.IsNullOrEmpty(invoice.InvoiceSerialID))
            {
                invoice.InvoiceSerialID = Guid.NewGuid().ToString();
            }

            if (distributionList != null)
            {
                foreach (var item in distributionList)
                {
                    HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.DistributionSerialID), "DistributionSerialID不为空");
                }
            }

            invoice.AuditStatus = 0;
            int state = DAL.DAL_PurchaseOrderDetail.AddInvoice_Distribution(invoice, distributionList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("添加发票信息：{0};处理时间:{1};)", invoice.InvoiceID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 添加发票关联配送单信息详情信息
        /// </summary>
        ///  <param name="invoice">发票信息 【InvoiceID】</param>
        /// <param name="distributionList">出库单信息列表【DistributionSerialID必填】</param>
        /// <returns></returns>
        public int AddInvoiceDistribution(HZ.DrugTrade.Model.Invoice invoice, IList<HZ.DrugTrade.Model.Distribution> distributionList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoice != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.InvoiceSerialID));

            foreach (var item in distributionList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.DistributionSerialID), "DistributionSerialID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.AddInvoiceDistribution(invoice, distributionList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("添加发票关联配送单信息详情信息：{0};处理时间:{1};)", invoice.InvoiceID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 删除发票关联配送单信息详情信息
        /// </summary>
        ///  <param name="invoice">发票信息 【InvoiceID】</param>
        /// <param name="distributionList">出库单信息列表【DistributionSerialID必填】</param>
        /// <returns></returns>
        public int DelInvoiceDistribution(HZ.DrugTrade.Model.Invoice invoice, IList<HZ.DrugTrade.Model.Distribution> distributionList)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoice != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.InvoiceSerialID));

            foreach (var item in distributionList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.DistributionSerialID), "DistributionSerialID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.DelInvoiceDistribution(invoice, distributionList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除发票关联配送单信息详情信息：{0};处理时间:{1};)", invoice.InvoiceID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 删除发票【含关联配送单信息详情信息】
        /// </summary>
        ///  <param name="invoice">发票信息 【InvoiceID】</param>
        /// <returns></returns>
        public int DelInvoice(HZ.DrugTrade.Model.Invoice invoice)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoice != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.InvoiceSerialID));
            int state = DAL.DAL_PurchaseOrderDetail.DelInvoice(invoice);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除发票【含关联配送单信息详情信息】：{0};处理时间:{1};)", invoice.InvoiceID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 删除发票_批量【含关联配送单信息详情信息】
        /// </summary>
        ///  <param name="invoiceList">发票信息列表 【InvoiceID】</param>
        /// <returns></returns>
        public int DelInvoice_Batch(IList<HZ.DrugTrade.Model.Invoice> invoiceList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in invoiceList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.InvoiceSerialID), "InvoiceSerialID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.DelInvoice_Batch(invoiceList);
            if (state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除发票_批量【含关联配送单信息详情信息】;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 查询发票号是否存在
        /// </summary>
        /// <returns></returns>
        public DataTable GetPurchaseNumber(string isID, string InvoiceID)
        {
            return DAL.DAL_PurchaseOrderDetail.GetPurchaseNumber(isID, InvoiceID);
        }

        /// <summary>
        /// 修改发票信息【发票号，发票时间】
        /// </summary>
        /// <param name="invoice">发票信息 </param>
        /// <returns>(0.不成功,1.成功,2.发票编号不存在)</returns>
        public int UpdateInvoice(HZ.DrugTrade.Model.Invoice invoice)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoice != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.InvoiceID));
            Common.ThrowHelper.Throw(invoice.InvoiceTime != null);
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoice.InvoiceSerialID));
            int state = DAL.DAL_PurchaseOrderDetail.UpdateInvoice(invoice);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("修改发票信息【发票号，发票时间】：{0};处理时间:{1};)", invoice.InvoiceID, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 分页获取发票明细信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Invoice> GetInvoiceByWhere(HZ.DrugTrade.Model.Query.Invoice where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_PurchaseOrderDetail.GetInvoiceByWhere(where, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 分页获取采购单配送详细信息【未开发票】
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.Distribution> GetPurchaseOrderDetail_DistributeNoInvoiceByWhere(HZ.DrugTrade.Model.Query.Distribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_DistributionRelation.GetPurchaseOrderDetail_DistributeNoInvoiceByWhere(where, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 添加发票回款单
        /// </summary>
        /// <param name="invoicePay">发票回款单信息</param>
        /// <param name="invoicelist">发票数组</param>
        /// <returns></returns>
        public int AddInvoicePay(InvoicePay invoicePay, IList<Invoice> invoicelist)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(invoicePay != null);
            //Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicePay.InvoicePayNo));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicePay.InvoicePaySerialID));
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(invoicePay.InvoicePayName));
            Common.ThrowHelper.Throw(invoicePay.PayAmount != null);
            Common.ThrowHelper.Throw(invoicelist != null);
            Common.ThrowHelper.Throw(invoicelist.Count > 0);
            foreach (var item in invoicelist)
            {
                Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.InvoiceSerialID));
            }

            invoicePay.InvoicePayTime = DateTime.Now;
            invoicePay.PayStatus = 0;

            int r = HZ.Data.DAL_Helper.OperateTableSQL<InvoicePay>(invoicePay, HZ.Data.TableOperator.Insert);

            if (r == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("添加发票回款单：{0};处理时间:{1};)", invoicePay.InvoicePayNo, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
                int n = DAL.DAL_Invoice.UpdateInvoicePay(invoicePay, invoicelist);
                return (n > 0) ? 1 : 0;
            }
            else
            {
                return r;
            }
        }

        /// <summary>
        /// 批量确认发票回款信息
        /// </summary>
        /// <param name="invoicePayList">发票回款单信息集合【InvoicePaySerialID必填】</param>
        /// <param name="isPass">true：通过；false：不通过</param>
        /// <returns></returns>
        public int ConfirmInvoicePay_Batch(IList<HZ.DrugTrade.Model.InvoicePay> invoicePayList, bool isPass)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in invoicePayList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.InvoicePaySerialID), "InvoicePaySerialID不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.ConfirmInvoicePay_Batch(invoicePayList, isPass);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量确认发票回款信息;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 分页获取未回款发票明细信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.InvoicePay> GetInvoiceNoPayByWhere(HZ.DrugTrade.Model.Query.InvoicePay where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            where.AuditStatus = 1;
            return DAL.DAL_PurchaseOrderDetail.GetInvoiceNoPayByWhere(where, currentpage, pagesize, out totalrecord);
        }


        /// <summary>
        /// 分页获取已回款发票明细信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.InvoicePay> GetInvoicePayByWhere(HZ.DrugTrade.Model.Query.InvoicePay where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            //where.AuditStatus = 1;     //update by lhl 2009-8-30  已回款的条件应该是paystatus is not null
            where.Append = " PayStatus is not null";
            return DAL.DAL_PurchaseOrderDetail.GetInvoicePayByWhere(where, currentpage, pagesize, out totalrecord);
        }


        /// <summary>
        /// 分页获取已回款发票汇总信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.InvoicePay> GetTotalInvoicePayByWhere(HZ.DrugTrade.Model.Query.InvoicePay where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            where.AuditStatus = 1;
            return DAL.DAL_PurchaseOrderDetail.GetTotalInvoicePayByWhere(where, currentpage, pagesize, out totalrecord);
        }



        /// <summary>
        /// 批量审核通过发票信息
        /// </summary>
        /// <param name="invoiceList">发票信息集合【InvoiceSerialID,AuditPerson必填】</param>
        /// <returns></returns>
        public int ConfirmInvoice_Batch(IList<HZ.DrugTrade.Model.Invoice> invoiceList,string[] arr)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in invoiceList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.InvoiceSerialID), "InvoiceSerialID不为空");
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.AuditPerson), "AuditPerson不为空");
            }
            int state = DAL.DAL_PurchaseOrderDetail.ConfirmInvoice_Batch(invoiceList,arr);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量审核通过发票信息;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 撤废发票
        /// </summary>
        /// <param name="invoiceList">发票信息集合【InvoiceSerialID,AuditPerson必填】</param>
        /// <returns></returns>
        public int DropInvoice_Batch(IList<HZ.DrugTrade.Model.Invoice> invoiceList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in invoiceList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.InvoiceSerialID), "InvoiceSerialID不为空");
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.AuditPerson), "AuditPerson不为空");
            }
            int state =  DAL.DAL_PurchaseOrderDetail.DropInvoice_Batch(invoiceList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("撤废发票;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 批量审核不通过发票信息
        /// </summary>
        /// <param name="invoiceList">发票信息集合【InvoiceSerialID,AuditPerson,NoPassReason必填】</param>
        /// <returns></returns>
        public int NoConfirmInvoice_Batch(IList<HZ.DrugTrade.Model.Invoice> invoiceList)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in invoiceList)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.InvoiceSerialID), "InvoiceSerialID不为空");
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.AuditPerson), "AuditPerson不为空");
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.NoPassReason), "NoPassReason不为空");
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.NoPassReason), "NoPassReason不为空");
            }
            int state =  DAL.DAL_PurchaseOrderDetail.NoConfirmInvoice_Batch(invoiceList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量审核不通过发票信息;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }


        /// <summary>
        /// 分页获取发票配送明细信息
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.InvoiceDistribution> GetInvoiceDistributionByWhere(HZ.DrugTrade.Model.Query.InvoiceDistribution where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_PurchaseOrderDetail.GetInvoiceDistributionByWhere(where, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 添加退货单明细
        /// </summary>
        /// <param name="returnMerchandise">待添加的退货单</param>
        /// <param name="detaillist">退货单明细</param>
        /// <returns>(0.不成功,1.成功,)</returns>
        public int AddReturnMerchandiseDetail_Batch(ReturnMerchandise returnMerchandise, IList<ReturnMerchandiseDetail> detaillist)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(returnMerchandise.ReturnSerialID != null, "");
            HZ.Common.ThrowHelper.Throw(detaillist.Count != 0, "");
            foreach (var item in detaillist)
            {
                HZ.Common.ThrowHelper.Throw(item.ReturnSerialDetailID != null, "明细ID自己赋值");
            }
            int state = DAL.DAL_ReturnMerchandise.AddReturnMerchandiseDetail_Batch(returnMerchandise, detaillist);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("添加退货单明细：{0};处理时间:{1};)", returnMerchandise.ReturnName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
            throw new NotImplementedException();
        }

        /// <summary>
        /// 判断退货产品是否在退货流程中 add by zdc
        /// </summary>
        /// <param name="procurecatalogID"></param>
        /// <param name="price"></param>
        /// <param name="orgID"></param>
        /// <returns></returns>
        public bool IsReturnning(string procurecatalogID, decimal? price, string orgID)
        {
            BLL_UserSession.CheckSession();
            return DAL_ReturnMerchandise.IsReturnning(procurecatalogID, price, orgID);

        }
       /// <summary>
       /// 是否开发票
       /// </summary>
       /// <param name="procurecatalogID"></param>
       /// <param name="price"></param>
       /// <param name="orgID"></param>
       /// <returns></returns>
       public bool IsInvoiced(string procurecatalogID)
        {
            BLL_UserSession.CheckSession();
            return DAL_ReturnMerchandise.IsInvoiced(procurecatalogID);

        }
        /// <summary>
        /// 分页获取退货单详情
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.ReturnMerchandiseDetail> GetReturnReturnMerchandiseDetail(HZ.DrugTrade.Model.Query.ReturnMerchandiseDetail where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            //HZ.DrugTrade.Model.Query.ReturnMerchandiseDetail mdl = where;
            //return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.ReturnMerchandiseDetail, Model.Query.ReturnMerchandiseDetail>(where, currentpage, pagesize, out totalrecord);
            //
            string condition = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where, true);
            string strsql = string.Format("SELECT a.*,case a.ReturnState when 0 then '未处理' when 1 then '已确认' else '拒绝' end  as ReturnStatedc FROM VIEW_RETURNMERCHANDISEDETAIL a  WHERE 1=1 {0}", condition);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(strsql, pagesize) { CurrentPage = currentpage };
            DataTable dt = pdes.GetSpecailPage();
            totalrecord = pdes.TotalCount;
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.ReturnMerchandiseDetail>(dt);

        }
        /// <summary>
        /// 分页获取退货单信息
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        public IList<Model.View.ReturnMerchandise> GetReturnReturnMerchandise(Model.Query.ReturnMerchandise where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.ReturnMerchandise, Model.Query.ReturnMerchandise>(where, currentpage, pagesize, out totalrecord);
        }
        /// <summary>
        /// 企业获取待确认退货单信息
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.ReturnMerchandise> GetReturnMerchandis_Company(HZ.DrugTrade.Model.Query.ReturnMerchandise where, string companyid, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_ReturnMerchandise.GetReturnReturnMerchandis_Company(where, companyid, currentpage, pagesize, out totalrecord);
            throw new NotImplementedException();
        }

        /// <summary>
        /// 医疗机构获取可退货产品列表
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.ReturnMerchandiseHospital> GetReturnMerchandis_Hospital(HZ.DrugTrade.Model.Query.ReturnMerchandiseHospital where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(where.HospitalID), "医疗机构ID不能空");
            return DAL.DAL_ReturnMerchandise.GetReturnMerchandis_Hospital(where, currentpage, pagesize, out totalrecord);
            throw new NotImplementedException();
        }

        /// <summary>
        /// 提交退货单
        /// </summary>
        /// <param name="ReturnMerchandise"></param>
        /// <returns></returns>
        public int SubmitReturnMerchandise(Model.ReturnMerchandise ReturnMerchandise)
        {
            BLL_UserSession.CheckSession();
            Common.ThrowHelper.Throw(!string.IsNullOrEmpty(ReturnMerchandise.ReturnSerialID), "ReturnSerialID不能空");
            ReturnMerchandise.ReturnOrderStatus = 1;
            int state = DAL.DAL_ReturnMerchandise.SubmitReturnMerchandise(ReturnMerchandise);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("提交退货单：{0};处理时间:{1};)", ReturnMerchandise.ReturnName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 获取未开票企业列表
        /// </summary>
        /// <param name="HospitalID">医疗机构OrgID</param>
        /// <returns>企业列表</returns>
        public IList<Company> GetUnInvoiceCompanyList(string HospitalID)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_Invoice.GetUnInvoiceCompanyList(HospitalID);
        }


        /// <summary>
        /// 获取未开票医疗机构列表
        /// </summary>
        /// <param name="CompanyID">企业ID</param>
        /// <returns>医疗机构列表</returns>
        public IList<Model.Hospital> GetUnInvoiceHospitalList(string CompanyID)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_Invoice.GetUnInvoiceHospitalList(CompanyID);
        }

        /// <summary>
        /// 获取未开票医疗机构列表 zdc
        /// </summary>
        /// <param name="CompanyID">企业ID</param>
        /// <returns>医疗机构列表</returns>
        public IList<Model.Hospital> GetUnInvoiceHospitalList(string CompanyID, string hospitalName,string where)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_Invoice.GetUnInvoiceHospitalList(CompanyID, hospitalName,where);
        }
        /// <summary>
        /// 获取未回款发票企业列表
        /// </summary>
        /// <param name="HospitalID">医疗机构ID</param>
        /// <returns></returns>
        public IList<Model.Company> GetUnPayCompanyList(string HospitalID, string CompanyName, int pagesize, int currentpage, out int totalcount)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_InvoicePay.GetUnPayCompanyList(HospitalID, CompanyName, pagesize, currentpage, out totalcount);
        }

        /// <summary>
        /// 获取历史有过交易记录的企业
        /// </summary>
        /// <param name="HospitalID">医疗机构编号</param>
        /// <param name="CompanyName">企业名称</param>
        /// <returns></returns>
        public System.Data.DataTable GetHistroyTradeCompany(string HospitalID, string CompanyName, string CompaynId, int pagesize, int currentpage, out int totalcount)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_InvoicePay.GetHistroyTradeCompany(HospitalID, CompanyName, CompaynId, pagesize, currentpage, out totalcount);
        }

        /// <summary>
        /// 获取历史有过交易记录的医疗机构
        /// </summary>
        /// <param name="HospitalID">医疗机构编号</param>
        /// <param name="HospitalName">企业名称</param>
        /// <returns></returns>
        public System.Data.DataTable GetHistroyTradeHospital(string HospitalID, string HospitalName, string CompaynId, int pagesize, int currentpage, out int totalcount)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_InvoicePay.GetHistroyTradeHospital(HospitalID, HospitalName, CompaynId, pagesize, currentpage, out totalcount);
        }

        /// <summary>
        /// 获取采购单明细已入库
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        public IList<Model.View.PurchaseOrderDetail> GetPurchaseOrderDetailInflow_ByWhere(Model.Query.PurchaseOrderDetail where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            where.Append = "WarehouseCount > 0";
            return GetPurchaseOrderDetailByWhere(where, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 根据回款单查询相关采购汇总信息
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        public System.Data.DataTable GetPurchaseSumQueryByInvoicePay(Model.Query.ProcureCatalog where, string InvoicePayID, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_Invoice.GetPurchaseSumQueryByInvoicePay(where, InvoicePayID, currentpage, pagesize, out totalrecord);
        }

        /// <summary>
        /// 批量提交退货单
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int SubmitReturnMerchandise_Batch_Hospital(IList<ReturnMerchandise> list)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in list)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.ReturnSerialID), "!string.IsNullOrEmpty(item.ReturnSerialID)");
                if (item.ReturnOrderStatus == 0)
                {
                    throw new ArgumentException("空单不要提交", "list");

                }
                item.ReturnOrderStatus = 2;
            }
            int state = DAL.DAL_ReturnMerchandise.SubmitReturnMerchandise_Batch_Hospital(list);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量提交退货单;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 批量删除退货单
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int DeleteReturnMerchandise_Batch_Hospital(IList<ReturnMerchandise> list)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in list)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.ReturnSerialID), "!string.IsNullOrEmpty(item.ReturnSerialID)");

            }
            int state = DAL.DAL_ReturnMerchandise.DeleteReturnMerchandise_Batch_Hospital(list);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量删除退货单;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 批量删除退货单明细
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int DeleteReturnMerchandiseDetail_Batch_Hospital(IList<ReturnMerchandiseDetail> list)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in list)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.ReturnSerialDetailID), "!string.IsNullOrEmpty(item.ReturnSerialDetailID)");

            }
            int state = DAL.DAL_ReturnMerchandise.DeleteReturnMerchandiseDetail_Batch_Hospital(list);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量删除退货单明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;

        }


        /// <summary>
        /// 批量更新退货明细
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int UpdateReturnMerchandiseDetail_Batch_Hospital(IList<ReturnMerchandiseDetail> list)
        {
            BLL_UserSession.CheckSession();
            foreach (var item in list)
            {
                HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(item.ReturnSerialDetailID), "!string.IsNullOrEmpty(item.ReturnSerialDetailID)");

            }
            int state = DAL.DAL_ReturnMerchandise.UpdateReturnMerchandiseDetail_Batch_Hospital(list);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("批量更新退货明细;处理时间:{0};)", DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }



        /// <summary>
        /// 根据配送企业编号分页获取未结算发票明细信息
        /// </summary>
        /// <param name="where">查询实体【配送企业编号必填，可选填：开票时间 发票号 发票总金额】</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns>未结算发票 【开票时间 发票号 发票总金额】</returns>
        public IList<HZ.DrugTrade.Model.View.Invoice> GetInvoiceByCompanyID_PS(Model.Query.Invoice where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(where != null);
            HZ.Common.ThrowHelper.Throw(!string.IsNullOrEmpty(where.CompanyID_PS), "配送企业编号必填!");
            //return DAL.DAL_PurchaseOrderDetail.GetInvoiceByWhere(where, currentpage, pagesize, out totalrecord);    //updated by lhl 2009-08-27 
            return DAL.DAL_PurchaseOrderDetail.GetInvoiceByCompanyID_PS(where, currentpage, pagesize, out totalrecord);
        }



        /// <summary>
        /// 删除一个结算单
        /// ()
        /// </summary>
        /// <param name="InvoicePay"></param>
        /// <returns>(1成功 0失败 2已有已确认发票)</returns>
        public int DeleteInvoicePay(Model.InvoicePay InvoicePay)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(InvoicePay.InvoicePaySerialID != null);
            int state = DAL.DAL_InvoicePay.DeleteInvoicePay(InvoicePay);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("删除一个结算单：{0};处理时间:{1};)", InvoicePay.InvoicePayNo, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }
        /// <summary>
        /// 更新一个结算单
        /// ()
        /// </summary>
        /// <param name="InvoicePay"></param>
        /// <param name="invoicelist"></param>
        /// <returns></returns>
        public int UpdateInvoicePay_Detail(Model.InvoicePay InvoicePay, IList<Invoice> invoicelist)
        {
            BLL_UserSession.CheckSession();
            HZ.Common.ThrowHelper.Throw(InvoicePay.InvoicePaySerialID != null);
            HZ.Common.ThrowHelper.Throw(invoicelist.Count > 0);
            foreach (var item in invoicelist)
            {
                HZ.Common.ThrowHelper.Throw(item.InvoiceID != null);
            }
            int state = DAL.DAL_InvoicePay.UpdateInvoicePay(InvoicePay, invoicelist);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("更新一个结算单：{0};处理时间:{1};)", InvoicePay.InvoicePayNo, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;
        }

        /// <summary>
        /// 企业获取已确认退货单信息
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        public IList<Model.View.ReturnMerchandise> GetTreatedReturnMerchandis_Company(Model.Query.ReturnMerchandise where, string companyid, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_ReturnMerchandise.GetTreatedReturnMerchandis_Company(where, companyid, currentpage, pagesize, out totalrecord);
        }
        /// 分页获取发票修改记录
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<Model.View.Invoice> GetAlterNote(Model.Query.Invoice InvoiceSerialID, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            string InvoiceID = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition<HZ.DrugTrade.Model.Query.Invoice>(InvoiceSerialID, true);

            string strsql = string.Format("SELECT * FROM TB_Invoice_update_log WHERE 1=1 {0} ", InvoiceID);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(strsql, pagesize) { CurrentPage = currentpage };
            DataTable dt = pdes.GetSpecailPage();
            totalrecord = pdes.TotalCount;
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.Invoice>(dt);
        }
        #endregion


        #region 采购单导入

        /// <summary>
        /// 检查给定的中标序号是否合格
        /// </summary>
        /// <param name="hospitalID"></param>
        /// <param name="procureCatalogIds"></param>
        /// <param name="errorProcureCatalog">输出不合格的中标序号</param>
        /// <returns></returns>
        public DataTable GetUnExistInSystemProcureCatalog(string hospitalID, string procureCatalogIds)
        {
            DataTable temp = new DataTable();
            string sql = @"select value from ufun_String_SplitTo_Table('" + procureCatalogIds + @"',',') 
where  value not in(
select distinct ProcureCatalogid from View_HospitalProcureCatalog With(noexpand)
where hospitalid ='" + hospitalID + @"' and isusing = '1' and length(companyid_ps) > 0)";

            temp = HZ.Data.DbHelperFactory.Create().ExecuteTable(sql);
            return temp;

        }

        /// <summary>
        /// 检查数据有无重复的中标序号
        /// </summary>
        /// <param name="procureCatalogIds"></param>
        /// <param name="DuplicateProcureCatalog"></param>
        /// <returns></returns>
        public DataTable GetDuplicateProcureCatalog(string procureCatalogIds)
        {
            DataTable temp = new DataTable();
            string sql = @"select value from (
select distinct value ,count(*) as num from ufun_String_SplitTo_Table('" + procureCatalogIds + @"',',') 
group by value) a 
where a.num >1";
            temp = HZ.Data.DbHelperFactory.Create().ExecuteTable(sql);

            return temp;
        }

        /// <summary>
        /// 导入采购单
        /// 优化速度
        /// </summary>
        /// <param name="simpleOrderDetailList"></param>
        /// <param name="newPurchaseorder"></param>
        /// <returns></returns>
        public int ImportPurchaseOrder(IList<Model.PurchaseOrderDetail> simpleOrderDetailList, HZ.DrugTrade.Model.PurchaseOrder newPurchaseorder)
        {
            //            string procureCatalogIDs = HZ.Data.DAL_Helper.GetModelFieldArrayString(simpleOrderDetailList, "ProcureCatalogID", ",",true);
            //            procureCatalogIDs = string.IsNullOrEmpty(procureCatalogIDs) ? "''" : procureCatalogIDs;

            //            //获取相关采购产品的价格及配送企业信息
            //            string sql = @"select * FROM  View_HospitalProcureCatalog With(noexpand)
            //                    where hospitalid = '" + newPurchaseorder.HospitalID+ "' and ProcureCatalogid in (" + procureCatalogIDs + ")";
            //            DataTable dt = HZ.Data.DbHelperFactory.Create().ExecuteTable(sql);

            //            IList<HZ.DrugTrade.Model.View.HospitalProcureCatalog> hospitalProcureCatalogList = null;
            //            hospitalProcureCatalogList = HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.HospitalProcureCatalog>(dt);

            //            //字典缓存
            //            IDictionary<string, HZ.DrugTrade.Model.View.HospitalProcureCatalog> dicache = new Dictionary<string, HZ.DrugTrade.Model.View.HospitalProcureCatalog>();
            //            foreach (HZ.DrugTrade.Model.View.HospitalProcureCatalog item in hospitalProcureCatalogList)
            //            {
            //                dicache.Add(item.ProcureCatalogID, item);
            //            }

            //            //构造正式采购单
            //            foreach (PurchaseOrderDetail orderDetail in simpleOrderDetailList)
            //            {
            //                orderDetail.OrderID = newPurchaseorder.OrderID;
            //                orderDetail.CompanyID_PS = dicache[orderDetail.ProcureCatalogID].CompanyID_PS;
            //                orderDetail.Price = dicache[orderDetail.ProcureCatalogID].Price;
            //                orderDetail.Amount = dicache[orderDetail.ProcureCatalogID].Price * orderDetail.PurchaseCount;
            //                orderDetail.FlowID = "1";
            //            }

            //添加采购明细
            BLL_UserSession.CheckSession();
            int state = DAL.DAL_PurchaseOrderDetail.ImportPurchaseOrderDetail_Batch(newPurchaseorder.OrderID, simpleOrderDetailList);
            if(state == 1)
            {
                BLL_Log.Instance.AddKeyOperationLog(new KeyOperationLog { OperateMessage = string.Format("导入采购单：{0};处理时间:{1};)", newPurchaseorder.OrderName, DateTime.Now.ToString()), ClientIP = HZ.Fun2.GetClientIP() });
            }
            return state;

        }


        #endregion

        /// <summary>
        /// 查询结算单状态
        /// add by Meng 2013-03-06
        /// </summary>
        /// <param name="qryWhere"></param>
        /// <returns></returns>
        public int SelectInvoiceState(HZ.DrugTrade.Model.InvoicePay qryWhere)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_InvoicePay.SelectInvoiceState(qryWhere);
        }
        /// <summary>
        /// 查询发票单状态
        /// add by Meng 2013-03-06
        /// </summary>
        /// <param name="qryWhere"></param>
        /// <returns></returns>
        public int SelectInvoiceStatus(string InvoiceSerialID)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_InvoicePay.SelectInvoiceStatus(InvoiceSerialID);
        }
        /// <summary>
        /// 查询该退货单是否存在
        /// </summary>
        /// <param name="where">查询实体</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="totalrecord">记录总数</param>
        /// <returns></returns>
        public IList<HZ.DrugTrade.Model.View.ReturnMerchandise> GetReturnReturnMerchandisewhere(string where, int currentpage, int pagesize, out int totalrecord)
        {
            BLL_UserSession.CheckSession();
            //HZ.DrugTrade.Model.Query.ReturnMerchandiseDetail mdl = where;
            //return HZ.DrugTrade.DAL2.DAL_Helper.GetPagedView<Model.View.ReturnMerchandiseDetail, Model.Query.ReturnMerchandiseDetail>(where, currentpage, pagesize, out totalrecord);
            //
            string strsql = string.Format("SELECT * FROM tb_ReturnMerchandise  WHERE 1=1 and returnserialid = '{0}'", where);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(strsql, pagesize) { CurrentPage = currentpage };
            DataTable dt = pdes.GetSpecailPage();
            totalrecord = pdes.TotalCount;
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.ReturnMerchandise>(dt);

        }
        /// <summary>
        /// 查询结算单状态
        /// add by Meng 2013-03-06
        /// </summary>
        /// <param name="qryWhere"></param>
        /// <returns></returns>
        public int SelectInvoiceStates(string InvoicePaySerialID)
        {
            BLL_UserSession.CheckSession();
            return DAL.DAL_InvoicePay.SelectInvoiceStates(InvoicePaySerialID);
        }
    }
}
